<template>
  <div class="app-container">
    <!-- 条件查询   -->
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item>
        <el-input v-model="queryParams.hosname" placeholder="医院名称"/>
      </el-form-item>
      <el-form-item>
        <el-input v-model="queryParams.hoscode" placeholder="医院编号"/>
      </el-form-item>
      <el-button type="primary" icon="el-icon-search" @click="getList()">查询</el-button>
      <el-button type="primary" icon="el-icon-search" @click="queryParams = {}">重置</el-button>
      <!-- 工具条 -->
      <div>
        <el-button type="danger" size="mini" @click="removeRows()"
                   :disabled="!multipleSelection||multipleSelection.length==0">批量删除
        </el-button>
      </div>
    </el-form>
    <!--列表 -->
    <el-table :data="list" stripe style="width: 100%" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="50"/>
      <el-table-column type="index" width="50" label="序号"/>
      <el-table-column prop="hosname" label="医院名称"/>
      <el-table-column prop="hoscode" label="医院编号"/>
      <el-table-column prop="apiUrl" label="api基础路径" width="200"/>
      <el-table-column prop="contactsName" label="联系人姓名"/>
      <el-table-column prop="contactsPhone" label="联系人手机"/>
      <el-table-column label="状态" width="80">
        <template slot-scope="scope">
          {{ scope.row.status === 1 ? '可用' : '不可用' }}
        </template>
      </el-table-column>
      <el-table-column label="操作" width="280" align="center">
        <template slot-scope="scope">
          <el-row>
            <el-col :span="8">
              <el-button type="danger" size="mini" icon="el-icon-delete" @click="removeDataById(scope.row.id)">删除
              </el-button>
            </el-col>
            <el-col :span="8">
              <router-link :to="'/hospSet/edit/'+(scope.row.id)">
                <el-button type="primary" size="mini" icon="el-icon-edit">编辑</el-button>
              </router-link>
            </el-col>
            <el-col :span="8">
              <el-button type="primary" size="mini" v-if="scope.row.status === 1 "
                         @click="lockHospSet(scope.row.id,scope.row.status)">锁定
              </el-button>
              <el-button type="danger" size="mini" v-else
                         @click="lockHospSet(scope.row.id,scope.row.status)">解除锁定
              </el-button>
            </el-col>
          </el-row>

        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :current-page="current"
      :page-size="limit"
      :total="total"
      style="padding:30px 0;text-align:center;"
      layout="total,prev,pager,next,jumper"
      @current-change="getList"
    />
  </div>
</template>

<script>
import { lockHospSet, getHospSetList, removeHospSet, batchRemoveHospitalSet } from '@/api/hospSet'

export default {
  name: 'list',
  data() {
    return {
      current: 1,
      limit: 5,
      total: 0,
      queryParams: {},
      list: [],
      multipleSelection: []
    }
  },
  created() {
    this.getList()
  },
  methods: {
    //修改锁定状态
    lockHospSet(id, status) {
      lockHospSet(id, status).then(res => {
        this.$message.success('操作成功!')
        this.getList()
      })
    },
    //批量删除
    removeRows() {
      this.$confirm('此操作将永久删除医院设置信息, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        batchRemoveHospitalSet(this.multipleSelection).then(res => {
          this.$message.success('删除成功!')
          this.getList()
        })
      }).catch(() => {
      })
    },
    handleSelectionChange(val) {
      this.multipleSelection = val.map(item => item.id)
    },
    //删除医院设置方法
    removeDataById(id) {
      this.$confirm('此操作将永久删除医院设置信息, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        removeHospSet(id).then(res => {
          this.$message.success('删除成功!')
          this.getList()
        })
      }).catch(() => {
      })
    },
    //医院设置列表方法
    getList(page = 1) {
      this.current = page
      getHospSetList(this.current, this.limit, this.queryParams).then(res => {
        console.log(res)
        this.list = res.data.records
        this.total = res.data.total
      })
    }
  }

}
</script>

<style scoped>

</style>
